package com.weilx959.spt.core.utils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileUtils {
    private FileUtils() {}

    /**
     * create f/path if not  exists
     * @param f file or path
     * @throws IOException create error
     */
    public static void createFileIfNotExists(String f) throws IOException {
        Assert.notBlank(f, "input file/path is blank!");
        Path path = Paths.get(f);

        if (Files.isDirectory(path)) {
            path.toFile().mkdirs();
        } else {
            path.getParent().toFile().mkdirs();

            if (!Files.exists(path)) {
                Files.createFile(path);
            }
        }
    }
}
